﻿Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports Seuss.EnterpriseLibrary.DataAccess
Imports Seuss.EnterpriseLibrary.BusinessLogic
Imports System.Web
Imports System.Data

Partial Class Consulta_AL_InfoAcad_HorAct
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Response.Expires = -1
        Response.AddHeader("Pragma", "no-cache")
        Response.AddHeader("cache-control", "private")
        Response.CacheControl = "no-cache"

        If Not Page.IsPostBack Then            
            Call CargarHorarioActual(CapturaPeriodoActual, IdentityUser.UserCode)
            Using Seguridad As New BLL_Administracion
                Seguridad.Set_Transaccion_Insert(Nothing, 100401, IdentityUser.UserCode, My.Request.UserHostAddress.ToString, CrearXMLTransaccion("Consulta Pagina Movil", "/Pagina|" + My.Request.Url.Segments(My.Request.Url.Segments.Length - 1).ToString))
            End Using
        End If
    End Sub

    Private Sub CargarHorarioActual(ByVal nPrdCodigo As String, ByVal cPerCodigo As Long)
        Dim ldr As New List(Of IDataReader)
        Dim DivPrincipal As New StringBuilder
        Dim DivEscuela As New StringBuilder
        Dim Escuela As String = ""
        Dim Asignatura As String = ""

        DivPrincipal.Append("<table border=0 width='100%'>")

        Using ObjPool As New PoolDbCommand()
            Dim ObjUsuario As New DAL_Kiosco(ObjPool.Database)
            ObjPool.AddDbCommand(ObjUsuario.Get_HorarioActualCorto_By_cPerCodigo_nPrdCodigo(cPerCodigo, nPrdCodigo), PoolDbCommand.PoolDbCommandResultType.Query)
            ObjPool.Pooling(Nothing, ldr, True)
            ObjUsuario = Nothing
            While ldr(0).Read
                If Escuela <> ldr(0).Item("Escuela").ToString Then
                    DivPrincipal.Append("<tr style='color:#FFFFFF'>")
                    DivPrincipal.Append("   <td style='font-size:12px;color:#000000; text-align:left;font-weight :bold' colspan='5'>ESCUELA DE " + ldr(0).Item("Escuela").ToString + "</td>")
                    DivPrincipal.Append("</tr><tr><td></td></tr>")
                End If

                If Asignatura <> ldr(0).Item("Asignatura").ToString Then
                    DivPrincipal.Append("<tr style='color:#FFFFFF'>")
                    DivPrincipal.Append("   <td style='background-color:#666666;font-size:12px;' colspan='5'>" + ldr(0).Item("Asignatura").ToString + " - Sec. " + ldr(0).Item("seccion").ToString + "</td>")
                    DivPrincipal.Append("</tr>")
                End If

                DivPrincipal.Append("<tr>")
                DivPrincipal.Append("   <td style='font-size:10px;width:8%;'>" + ldr(0).Item("Dia").ToString + "</td>")
                DivPrincipal.Append("   <td style='font-size:10px;width:10%;'>" + ldr(0).Item("Inicio").ToString + "</td>")
                DivPrincipal.Append("   <td style='font-size:10px;width:12%;'>" + ldr(0).Item("Fin").ToString + "</td>")
                DivPrincipal.Append("   <td style='font-size:10px;width:28%;'>" + ldr(0).Item("cIntDescripcion").ToString + "</td>")
                DivPrincipal.Append("   <td style='font-size:10px;width:42%;'>" + ldr(0).Item("Docente").ToString + "</td>")
                DivPrincipal.Append("</tr>")

                Escuela = ldr(0).Item("Escuela").ToString
                Asignatura = ldr(0).Item("Asignatura").ToString
            End While
        End Using

        DivPrincipal.Append("</table>")
        lblHorarioActual.Text = DivPrincipal.ToString
    End Sub

    Public Function CapturaPeriodoActual() As Integer
        Dim nPrdCodigo As Integer = 0
        Dim ldr As New List(Of IDataReader)
        Using ObjPool As New PoolDbCommand()
            Dim ObjMenu As New DAL_Kiosco(ObjPool.Database)
            ObjPool.AddDbCommand(ObjMenu.Get_PeriodoAcademico_Actual(), PoolDbCommand.PoolDbCommandResultType.Query)
            ObjPool.Pooling(Nothing, ldr, True)
            If ldr(0).Read Then
                nPrdCodigo = ldr(0).GetInt32(0)
            Else
                nPrdCodigo = 0
            End If
        End Using
        ldr(0).Close()
        ldr(0) = Nothing
        Return nPrdCodigo
    End Function
End Class
